package logic

import (
	"context"
	"fmt"
	"health/model/mysql"

	"health/registerrpc/internal/svc"
	"health/registerrpc/registerrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelLogic {
	return &DelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DelLogic) Del(in *registerrpc.DelRequest) (*registerrpc.DelResponse, error) {
	// todo: add your logic here and delete this line
	var del mysql.Register
	err := mysql.DB.Debug().Where("id = ?", in.Id).Delete(&del).Error
	if err != nil {
		return nil, fmt.Errorf("删除失败")
	}
	return &registerrpc.DelResponse{}, nil
}
